package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.common.domain.query.PageQuery;
import com.tianji.common.utils.CollUtils;
import com.tianji.learning.domain.dto.LearningPlanDTO;
import com.tianji.learning.domain.vo.LearningLessonVO;
import com.tianji.learning.domain.vo.LearningPlanPageVO;
import com.tianji.learning.service.ILearningLessonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 学生课程表 前端控制器
 * </p>
 *
 * @author lyh
 * @since 2024-12-03
 */
@Api(tags = "我的课表相关接口")
@RestController
@RequestMapping("/lessons")
@RequiredArgsConstructor
public class LearningLessonController {

    private final ILearningLessonService lessonService;

    @ApiOperation("查询我的课表")
    @GetMapping("/page")
    public PageDTO<LearningLessonVO> queryMyLessons(PageQuery query) {
        return lessonService.queryMyLessons(query);
    }

    @GetMapping("/now")
    @ApiOperation("查询我正在学习的课程")
    public LearningLessonVO queryMyCurrentLesson() {
        return lessonService.queryMyCurrentLesson();
    }
  @DeleteMapping("{courseId}")
  @ApiOperation("删除失效的课程")
  public void deletelesson(@PathVariable Long courseId){
      lessonService.deletelession(null, CollUtils.toList(courseId));
  }

    /**
     * 检查课程是否有效
     * @param courseId
     * @return
     */
    @GetMapping("/{courseId}/valid")
    @ApiOperation("检查课程是否有效")
    public Long isLessonValid(@PathVariable("courseId") Long courseId){
       return  lessonService.isLessonValid(courseId);
    }
    @ApiOperation("查询用户课表中指定课程状态")
    @GetMapping("/{courseId}")
    public LearningLessonVO getByCourseId(@PathVariable("courseId") Long courseId){
      return lessonService.getByCourseIdAndUserId(courseId);
    }

    /**
     * 统计课程学习人数
     * @param courseId 课程id
     * @return 学习人数
     */
    @GetMapping("/{courseId}/count")
    Integer countLearningLessonByCourse(@PathVariable("courseId") Long courseId){
        return lessonService.countLearningLessonByCourse(courseId);
    }
    @PostMapping("/plans")
    public void lessonPlan(@RequestBody LearningPlanDTO dto){
        lessonService.lessonPlan(dto);
    }
    @GetMapping("/plans")
    public LearningPlanPageVO getMyPlan(PageQuery pageQuery){
     return lessonService.getMyPlan(pageQuery);
    }
}
